<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
       <form action="hello/hi" method="post">
         <input type="text" name="hello" value="这是前端传输过来的">
         <input type="submit" value="提交数据">
       </form>

       <br>
       测试json请求： <br>
       <textarea name="" id="content" style="width: 50%;height: 400px">{"name": "<script>alert(111)</script>",
"date":"2020-09-09",
"classIds":[1,2,3,4],
"person":{"id":0, "name": "wahaha", "addr":"山东威海"},
"personList":[
{"id":1, "name": "lisi", "addr":"山东威海"}
],
"persons":[
{"id":2, "name": "wangwu", "addr":"山东威海haha"}
],
"map":{
"lisi":{"id":1, "name": "lisi", "addr":"山东威海"},
"wangwu":{"id":2, "name": "wangwu", "addr":"山东威海haha"}
}
}</textarea>
       <br>
       <div id="result"></div>
       <textarea name="" id="result2" cols="30" rows="10"></textarea>
       <button type="button" onclick="demoAxiosPost()">提交JSON格式Ajax请求</button>
       <button type="button" onclick="demoAjaxPost()">提交普通格式Ajax请求</button>
  </body>

  <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>


  <script>
      function demoAxiosPost() {
          var data = JSON.parse(document.getElementById("content").value);
          console.log(data);
          axios.post("/hello/ajaxOne/111?age=32", data).then(function (value) {
              document.getElementById("result").innerHTML = value.data.result;
              document.getElementById("result2").value = value.data.result;
          })
      }

      function demoAjaxPost() {
          var data = JSON.parse(document.getElementById("content").value);
          $.ajax({
              url: "/hello/ajaxTwo/111?age=32",
              type: "post",
              dataType: "json",
              data: data,
              success: function (data) {
                  console.log(data);
              }

          })
      }
  </script>
</html>
